﻿<%@ WebHandler Language="C#" Class="index" %>

using Models;
using System;
using System.Web;
using Newtonsoft.Json;
using System.Linq;
using Newtonsoft.Json.Linq;
using System.Collections;


public class index : IHttpHandler {

    public void ProcessRequest(HttpContext context) {
        context.Response.ContentType = "text/plain";
        Uri uri = HttpContext.Current.Request.Url;
        String host = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port;

        //paramJson: {"city":"昆明","pageNo":1,"pageSize":10}

        //  var xxx=HttpContext.Current.Request.Form["paramJson"];
        //JObject jo = (JObject)JsonConvert.DeserializeObject(xxx);

        var code = 1;
        var msg = "获取成功";
        var time = DateTime.Now;

        using (Entities bll = new Entities())
        {

            ArrayList listjson = new ArrayList();

            //     showmenu: [{typeName:"21",menuContent:[{pic:"/images/a.jpg","foodName":"dsad","price":3,numb:0},{pic:"/images/a.jpg","foodName":"88976","price":7,numb:0}]},
            //  {typeName:"222",menuContent:[{"foodName":"33","price":3,numb:0},{"foodName":"4","price":7,numb:0}]}
            //SCCLASSID=1 景区
            var data = bll.S_Classs.ToList();//全部.ToList();

            foreach (var x in data)
            {

                var mygoods = bll.S_Goods.Where(p=>p.SCCLASSID==x.SCID).OrderByDescending(xx=>xx.GSort).ToList();//全部.ToList();

                var GetImgs = methods.getFirstImg(x.SCIMG);
                ArrayList listgood = new ArrayList();

                foreach (var gg in mygoods)
                {

                    var GetGimg = methods.getFirstImg(gg.GImg);
                    listgood.Add(new
                    {
                        foodName = gg.GName,
                        id = gg.GID,
                        pic=GetGimg,
                        tag = gg.G_Introduce,
                        price = gg.GPrice,
                        numb = 0,
                        gg.Gdw,
                        content=gg.GContent.Replace("src=\"/upload/","src=\""+host+"/upload/"),
                    });
                }



                listjson.Add(new
                {
                    typeName = x.SCNmae,
                    GetImgs,
                    menuContent = listgood

                });

         

                var total = data.Count();

            }

                 String[] ad ={ "/Up/ad.png","/Up/ad2.png" };

                var seller = new
                {
                    business_end = "21:00",
                    logourl = host+"/images/logo.png",
                    name = "小熊工厂洗--演示系统 请勿下单",
                    min_amount = "99",
                    business_start = "11:03",
                    address = "2东路269号",
                    notice = "洗衣洗鞋新时尚",
                    telephone = "13378719129",
                    tel="0871-66227317",  
                    express_fee = "1",
                    ad


                };

            context.Response.Write(JsonConvert.SerializeObject(new { code, msg, time, data=listjson,seller}));

            HttpContext.Current.Response.End();
            //context.Response.Write("Hello World");


        }
    }

    public bool IsReusable {
        get {
            return false;
        }
    }




}